from fastapi import APIRouter, status
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from fastapi import Request

from app.controllers.auth_controllers import (LoginController,
                                              RegistrationController)
from app.schemas.auth_schemas import (LoginRequestSchema, LoginResponseSchema,
                                      RegistrationRequestSchema,
                                      RegistrationResponseSchema)

auth_router = APIRouter(tags=["Auth routers"])
templates = Jinja2Templates(directory="templates")


@auth_router.post("/registration", status_code=status.HTTP_201_CREATED)
async def register_user(
        request: RegistrationRequestSchema,
) -> RegistrationResponseSchema:
    controller = RegistrationController(request=request)
    return await controller.execute()


@auth_router.post("/login", status_code=status.HTTP_200_OK)
async def login_user(request: LoginRequestSchema) -> LoginResponseSchema:
    controller = LoginController(request=request)
    return await controller.execute()


@auth_router.get("/login", response_class=HTMLResponse)
async def login_user_front(request: Request):
    return templates.TemplateResponse(
        request=request, name="login.html", context={"id": 1}
    )


@auth_router.get("/registration", response_class=HTMLResponse)
async def register_user_front(request: Request):
    return templates.TemplateResponse(
        request=request, name="register.html", context={"id": 1}
    )
